import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import Home from '../views/Home.vue';
import Cate from '../views/Cate.vue';
import Login from "../views/login.vue";
import Register from "../views/register.vue";
import Guide from "../views/Guide.vue";


const routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        name: 'home',
        component: Home
    },
    {
        path: '/cate',
        name: 'cate',
        component: Cate
    },
    {
        path: '/login',
        name: 'login',
        component: Login
    },
    {
        path: '/register',
        name: 'register',
        component: Register
    },
    {
        path: '/guide',
        name: 'guide',
        component: Guide
    }



];
const router = createRouter({
    history: createWebHashHistory(),
    routes
});
router.beforeEach((form, to, next) => {
    if (to.path === '/home' || form.path === '/home') {
        let isVisted = localStorage.getItem('isVisted') || 'false';
        if(isVisted) {
            return next();
        }else{
            localStorage.setItem('isVisted', 'true');
            return next('/guide');
        }
    }
    next();
})

export default router;